package com.suke.czx.modules.examstack.controller;

import java.util.List;
import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestBody;
import com.suke.czx.modules.examstack.entity.User2GroupEntity;
import com.suke.czx.modules.examstack.service.User2GroupService;
import com.suke.czx.common.utils.PageUtils;
import com.suke.czx.common.utils.Query;
import com.suke.czx.common.utils.R;




/**
 * 
 * 
 * @author Larry
 * @email lawhw@163.com
 * @date 2018-11-01 23:17:48
 */
@RestController
@RequestMapping("/exam/user2group")
public class User2GroupController {
    @Autowired
    private User2GroupService user2GroupService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("exam:user2group:list")
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);

        List<User2GroupEntity> user2GroupList = user2GroupService.queryList(query);
        int total = user2GroupService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(user2GroupList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{groupId}")
    @RequiresPermissions("exam:user2group:info")
    public R info(@PathVariable("groupId") Integer groupId){
			User2GroupEntity user2Group = user2GroupService.queryObject(groupId);

        return R.ok().put("user2Group", user2Group);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("exam:user2group:save")
    public R save(@RequestBody User2GroupEntity user2Group){
			user2GroupService.save(user2Group);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("exam:user2group:update")
    public R update(@RequestBody User2GroupEntity user2Group){
			user2GroupService.update(user2Group);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("exam:user2group:delete")
    public R delete(@RequestBody Integer[] groupIds){
			user2GroupService.deleteBatch(groupIds);

        return R.ok();
    }
	
}
